package com.robot.controller;

import com.robot.mcp.MCPOrchestrator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * Controller for MCP operations
 * Simplified to only include necessary endpoints
 */
@RestController
@RequestMapping("/api/mcp")
public class MCPController {

    @Autowired
    private MCPOrchestrator mcpOrchestrator;

    /**
     * Process a natural language query
     */
    @PostMapping("/process")
    public Map<String, Object> processIntent(@RequestBody Map<String, String> request) {
        Map<String, Object> response = new HashMap<>();

        String input = request.get("query");
        if (input == null || input.trim().isEmpty()) {
            response.put("success", false);
            response.put("message", "输入不能为空");
            return response;
        }

        String result = mcpOrchestrator.process(input);

        response.put("success", true);
        response.put("response", result);
        return response;
    }

    /**
     * Process a chat message
     */
    @PostMapping("/chat")
    public Map<String, Object> chat(@RequestBody Map<String, String> request) {
        Map<String, Object> response = new HashMap<>();

        String input = request.get("message");
        if (input == null || input.trim().isEmpty()) {
            response.put("success", false);
            response.put("message", "消息不能为空");
            return response;
        }

        String result = mcpOrchestrator.chat(input);

        response.put("success", true);
        response.put("response", result);
        return response;
    }
}
